package com.example.skudemo.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RedisToken {
    private static String jwtKey;

    @Value("${jwt.secret}")
    public void setJwtKey(String jwtKey) {
        RedisToken.jwtKey = jwtKey;
    }

    /**
     * 根据用户id来生成一个唯一的值
     *
     * @param userId
     * @return
     */
    public static String generateToken(Integer userId) {
        String currentTimeStr = Long.toString(DateUtils.getCurrentTime());
        String md5Value = Md5Utils.getMd5(String.format("%d",userId).concat(currentTimeStr).concat(RedisToken.jwtKey));
        return md5Value.concat(currentTimeStr.substring(0, 8));
    }
}
